/**
 * 在全局多个组件中共享的“管理员相关数据”
 */
import { defineStore } from "pinia"
import { computed, ref } from "vue"

export const useAdminStore = defineStore('admin', ()=>{
    //Store中的第一部分内容(必需）：Store.State => ref/reactive
    const adminName = ref('root')
    const adminAge = ref(20)
    const adminToken = ref('')

    //Store中的第二部分内容(可选)：Store.Getter => computed
    const adminNameUpper = computed(()=>{
        console.log('Store正在把小写字母转换为大写') 
        return adminName.value.toUpperCase() + '-NEW'
    })

    //Store中的第三部分内容(可选)：Store.Action => methods
    const addAge = ()=>{
        //console.log(adminAge)
        adminAge.value ++
    }
    // const adminNameToUpper = ()=>{
    //     console.log('Store正在把小写字母转换为大写') 
    //     return adminName.value.toUpperCase()
    // }
    
    return {
        adminName, 
        adminAge, 
        addAge, 
        /*adminNameToUpper*/ 
        adminNameUpper,
        adminToken
    }        //返回Store对象
}, {
    // persist: true           //指定刚刚创建的Store需要持久化存储，默认存储在localStorage
    persist: {
        storage: sessionStorage
    }
})